class Solution(object):
    def merge(self, intervals):
        """
        :type intervals: List[List[int]]
        :rtype: List[List[int]]
        """
        i = 0
        while i < len(intervals):
            flag = 0
            for j in range(i + 1, len(intervals)):
                if intervals[i][0] <= intervals[j][0] <= intervals[i][1] or intervals[j][0] <= intervals[i][0] <= intervals[j][1]:
                    min_value = min(intervals[i][0], intervals[j][0])
                    max_value = max(intervals[i][1], intervals[j][1])
                    intervals[i][0] = min_value
                    intervals[i][1] = max_value
                    del intervals[j]
                    flag = 1
                    break
            if flag == 0:
                i += 1
        return intervals


data = Solution()
intervals = [[1,4],[4,5]]
print(data.merge(intervals))